from typing import List, Optional
from pydantic import BaseModel
from datetime import datetime
from enum import Enum

from app.schemas.user import UserBrief
from app.models.chat import ChatType

# 消息基础模式
class MessageBase(BaseModel):
    content: str
    content_type: str = "text"  # text, image, video, audio, file
    media_url: Optional[str] = None

# 创建消息
class MessageCreate(MessageBase):
    pass

# 消息信息
class Message(MessageBase):
    id: int
    chat_id: int
    sender_id: Optional[int] = None
    sender: Optional[UserBrief] = None
    is_read: bool
    created_at: datetime
    
    class Config:
        orm_mode = True

# 聊天会话基础模式
class ChatBase(BaseModel):
    chat_type: ChatType
    name: Optional[str] = None
    campsite_id: Optional[int] = None

# 创建私聊
class PrivateChatCreate(BaseModel):
    recipient_id: int  # 接收方用户ID

# 创建群聊
class GroupChatCreate(BaseModel):
    name: str
    campsite_id: Optional[int] = None
    participant_ids: List[int] = []  # 参与者用户ID列表

# 聊天参与者
class ChatParticipantBase(BaseModel):
    is_admin: bool = False

# 聊天参与者信息
class ChatParticipant(ChatParticipantBase):
    id: int
    chat_id: int
    user_id: int
    user: UserBrief
    last_read_message_id: Optional[int] = None
    created_at: datetime
    updated_at: Optional[datetime] = None
    
    class Config:
        orm_mode = True

# 聊天会话简要信息
class ChatBrief(BaseModel):
    id: int
    chat_type: ChatType
    name: Optional[str] = None
    campsite_id: Optional[int] = None
    last_message: Optional[Message] = None
    unread_count: int = 0
    created_at: datetime
    
    class Config:
        orm_mode = True

# 聊天会话详细信息
class Chat(ChatBase):
    id: int
    participants: List[ChatParticipant] = []
    created_at: datetime
    updated_at: Optional[datetime] = None
    
    class Config:
        orm_mode = True 